import { ApiProperty, ApiExtraModels, getSchemaPath } from "@nestjs/swagger";
import { IsNumber, IsString, IsOptional, IsEmpty, ValidateNested } from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { VillageAction } from "./village-action.entity";
import { Village } from "./village.entity";
import { CrudValidationGroups } from "@nestjsx/crud";
import { BaseEntity } from "./base.entity";
import { Group } from "./group.entity";

const { CREATE, UPDATE } = CrudValidationGroups;


@Entity()
export class VillageActionType extends BaseEntity {

  @ApiProperty({
    description: '村组织活动类型 -主键',
    required: false
  })
  @PrimaryGeneratedColumn()
  id  ?: number;

  @ApiProperty({
    example: 1,
    description: '所属村',
    required: true,
    oneOf: [
      {
        type: 'Number'
      },
      {
        $ref: getSchemaPath(() => Village)
      }
    ]
  })
  @ManyToOne(() => Village, Village => Village.villageActionType, {
    eager: true
  })
  village:  Number |  Village

  
  @ApiProperty({
    example: '村组织活动类型名字',
    description: '村组织活动类型名字',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
  })
  name: string

  @ApiProperty({
    example: 1,
    description: '村组织活动',
    required: false,
    type: Number
  })
  @OneToMany(() => VillageAction, VillageAction => VillageAction.type)
  villageAction: VillageAction
}